<?php
$version = Zend_Registry::get('version');
echo $this->headScript()->setFile($this->baseUrl().'/js/jquery/table-sorter/jquery.dataTables.js');
?>

<script type="text/javascript">
$(document).ready(function() {	
	<?php if ($this->allow('privilege')) : ?>
	/****************************Sorting Table Start*********************/
	var oTable = $("#sortTable").dataTable({
				"bPaginate": false,
				"bLengthChange": true,
				"bSearchable": true,
				"bFilter": true,
				"bSort": true,
				"bInfo": false,
				"bAutoWidth": true,
				"bProcessing": false,
				"bSortClasses": true,
				"bStateSave": false,
				"bServerSide": false,
				"aaSorting": [[ 0, "asc" ]],
				"oLanguage" : { "sSearch": "<?php echo $this->translator->translator('jquery_filter'); ?>" }
			}); 	
	
	$('td', oTable.fnGetNodes()).hover( function() {		
		$(this).parents("tr:first").children('td').addClass( 'highlighted' );
	}, function() {
		$('td.highlighted').removeClass('highlighted');
	} );
	lastClassAdd(oTable);	
	/****************************Sorting Table End*********************/
	<?php endif; ?>
	function openMsgDialog(msg)
	{
		$('#dialog_msg').html(msg).dialog({
			autoOpen: true,
			modal: true,
			show: 'explode',
			width : 'auto',
			resizable: true,				
			buttons: [{ text: "<?php echo html_entity_decode($this->translator->translator('common_ok'), ENT_QUOTES, 'UTF-8'); ?>", click: function() { $(this).dialog('option', 'hide', 'explode').dialog("close"); } } ],
			open: function(event, ui)
				 {
					setTimeout(function() 
					{									
						if($('#' + event.target.id).dialog('isOpen'))
						{
							$('#' + event.target.id).dialog('option', 'hide', 'explode').dialog('close');										
						}
					}, 12000);
				  }
		});
	}
	
	$("#upload-form").dialog({
		autoOpen: false,
		width: 910,
		height: 655,
		show: 'fade',			
		modal: true
	});	

	$('a.upload_btn').click(function() {
		var src = $("#i-upload-form").attr("src");		
			$("#i-upload-form").attr("src", "<?php echo $this->url( array('module' => 'Projects','controller' => 'Index', 'action'   => 'file' ), 'adminrout',    false) ?>");			
			$('#upload-form').dialog('open');		
	});	
	
	$('a.set_privillege_btn').click(function() {
		var user_info = $(this).attr('rel');	
		var src = $("#i-upload-form").attr("src");		
			$("#i-upload-form").attr("src", "<?php echo $this->url( array('module' => 'Projects','controller' => 'Index', 'action'   => 'file', 'user_info' => '' ), 'adminrout',    false) ?>"+user_info);			
			$('#upload-form').dialog('open');		
	});
	
	$('a.select_file_btn').click(function() {		 
		
			var currentIFrame = $('#i-upload-form');
			var v = currentIFrame.contents().find("#file_name").val();
			if(v == '' || v == null)
			{
				var msg = '<?php echo $this->translator->translator("insert_selected_file_err"); ?>';				
				openMsgDialog(msg);
			}
			else
			{
				var file_arr =  v.split(',');							
				var img_code = '<span class="thumb"><img src="'+file_arr[0]+'/'+file_arr[1]+'" width="45" height="35" class="bdr" /></span>';
				$('#selected_file').html(img_code);
				$('#category_thumb').val(file_arr[1]);
				$("#upload-form").dialog('option','hide','explode').dialog('close');
				imageThumbnil();
			}
		});
	
	$('a.close_dialog_btn').click(function() {	
		$("#i-upload-form").attr("src", ''); 	 
		$("#upload-form").dialog('option','hide','explode').dialog('close');			
	});
		
	$('a.reset_btn').click(function() {			
		 resetFields();		
	});
	
	function resetFields()
	{
		$( "form" )[ 0 ].reset();		
		$('#selected_file').html('');				
		$('#categoryTree').html('');
		$('#category_parent').val('0');
		$('#category_thumb').val('');
		$('#dataId').html('Root (0)');		
		if(tinyMCE.get('category_desc'))
		{
			tinyMCE.get('category_desc').setContent('');
		}
	}
	
	function removeError()
	{
		$('#category_name_err').html('');
		$('#category_name').removeClass('ui-state-error');
		$('#category_title_err').html('');
		$('#category_title').removeClass('ui-state-error');
		$('#group_id_err').html('');
		$('#group_id').removeClass('ui-state-error');
		$('#category_desc_err').html('');
		$('#category_desc').removeClass('ui-state-error');
		$('#category_thumb_err').html('');
		$('#category_thumb').removeClass('ui-state-error');
		
		$('#actionMessage').attr('class','none');
		$('#actionMessage').html('&nbsp;');
	}
	
	function addError(key,errMsg)
	{
		var err_id = key+'_err';
		var field_name = key;
		$('#'+field_name).addClass('ui-state-error');
		$('#'+err_id).append(errMsg);
	}
	
	function openLoaderDialog()
	{
		$('#dialog_container').dialog({
					autoOpen: true,
					modal: true,
					show: 'fade',
					resizable: 'false',				
					open: function(event, ui)
						 {
						 	$("#progressbar").progressbar({
								value:100
				
							});							
						  }
				});
	}
	
	function closeLoaderDialog()
	{
		$('#dialog_container').dialog('option','hide','explode').dialog('close');
	}
	
});	



function getFileExtension(filename)
{
	return filename.replace(/^.*?\.([a-zA-Z0-9]+)$/, "$1");
}

</script>

<div id="container">
<?php if (!$this->allow('index')) : ?>
	<div class="grid_12 t_a_bottom">
		<?php echo $this->translator->translator('Member_Access_deny_desc'); ?>
	</div>
<?php else : ?>

<div class="title-container">
	<div class="user-privilege-set"><h1><?php echo $this->translator->translator('projects_privilege_list_page_name'); ?></h1></div>
</div>

<div class="content-container">
	<div id="sidebar-inner">
    	<?php echo $this->partial('index/member_menu.phtml');  ?>
   	</div>
	<div id="content-inner">
    	<?php if (!$this->allow('privilege')) : ?>
        	<div class="button-container">
            	<div class="button"><a href="javascript:void(0);" class="upload_btn"><?php echo $this->translator->translator('projects_file_manager_page_name'); ?></a></div>
			</div>
        <?php else: ?>
        
        <div class="pagination">
            <?php echo $this->paginationControl($this->member_datas, 'Sliding', 'index/top_pagination.phtml'); ?>
        </div>
        <div class="chart">
        	<div id="member_list" class="data-table">
				<table id="sortTable" width="100%" align="center" cellpadding="0" cellspacing="0">
					<thead>
				  		<tr>
                            <th width="4%"><?php echo $this->translator->translator('projects_privilege_list_page_id'); ?></th>
                            <th width="22%"><?php echo $this->translator->translator('projects_privilege_list_page_user'); ?></th>
                            <th width="14%"><?php echo $this->translator->translator('projects_privilege_list_page_first'); ?></th>
                            <th width="14%"><?php echo $this->translator->translator('projects_privilege_list_page_last'); ?></th>
                            <th width="15%"><?php echo $this->translator->translator('projects_privilege_list_page_org'); ?></th>
                            <th width="23%"><?php echo $this->translator->translator('projects_privilege_list_page_email'); ?></th>
                            <th width="8%"><?php echo $this->translator->translator('common_action'); ?></th>
				  		</tr>
				  	</thead>
				  	<tbody>
				  	<?php 
						$members_role = new Members_Model_DbTable_Role();
						$j = 1;
						foreach ($this->member_datas as $entry): 
							if($j % 2 == 0)
							{
								$onmouseout = "this.bgColor='#FFFFFF';";
								$background = '#FFFFFF';
							}
							else
							{
								$onmouseout = "this.bgColor='#F7F7F7';";
								$background = '#F7F7F7';
							}
							$roleInfo = $members_role->getRoleInfo($entry->role_id);
					?>
				  		<tr bgcolor="<?php echo $background; ?>" onmouseover="this.bgColor='#FCF5DD';" onmouseout="<?php echo $onmouseout; ?>">
							<td class="center" id="u_id<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->user_id); ?></td>
                            <td id="u_username<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->username); ?></td>
                            <td id="u_firstname<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->firstName); ?></td>
                            <td id="u_lastname<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->lastName); ?></td>
                            <td id="u_company<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->companyName); ?></td>
                            <td id="u_emailAddress<?php echo $this->escape($entry->user_id); ?>"><?php echo $this->escape($entry->username); ?></td>
                            <td class="center" id="u_delete<?php echo $this->escape($entry->user_id); ?>">
                                <?php if ($this->allow('privilege')) : if($roleInfo['role_lock'] == '1'): ?>
                                	<a href="javascript:void(0);" rel="<?php echo $this->escape($entry->user_id).','.$this->escape($entry->firstName); ?>" class="set_privillege_btn" title="<?php echo $this->translator->translator('common_set_privilege'); ?>"><img src="application/modules/Administrator/layouts/scripts/images/tools/privilege-setting.gif" alt="<?php echo $this->translator->translator('common_set_privilege'); ?>" border="0" /></a>
                                <?php endif; endif; ?>
                           	</td>
						</tr>
				  	<?php 
						$j++;
						endforeach;	
				  	?>
				  	</tbody>
				</table>
			</div>
		</div>
        <div class="pagination">
            <?php echo $this->paginationControl($this->member_datas, 'Sliding', 'index/pagination.phtml'); ?>
        </div>
        <?php endif; ?>
	</div>
</div>
<?php endif; ?>

<div id="dialog_msg" title="<?php echo $this->translator->translator('common_dialog_msg','Message'); ?>"></div> 
<div id="dialog_container" style="display:none" title="<?php echo $this->translator->translator('common_processing_language'); ?>">
	<div id="progressbar" ></div>	
</div>

<div id="upload-form" title="<?php echo $this->translator->translator('projects_file_manager_dialog'); ?>">
	<div>
    	<iframe id="i-upload-form" src="" class="iframe-img-upload" style="height:520px"></iframe>        
    </div>
    <div class="button-container">
        <span class="button ui-widget-content-1"><a href="javascript:void(0);" class="close_dialog_btn"><span class="icon close"><?php echo $this->translator->translator('common_close'); ?></span></a></span>
    </div>
</div>
</div>